<%= page_title "User Permission Reports" %>

<section>
  <div class="csv-users-filters clearfix">
    <%= form_tag new_csv_export_path(format: :csv, type: :users), method: :get, class: "form-horizontal" do %>
      <%= hidden_field_tag :type, "users" %>

      <div class="form-group">
        <div class="col-lg-offset-2 col-lg-10 checkbox">
          <%= label_tag do %>
            <%= check_box_tag :inherited, true %>
            Show inherited project permissions
          <% end %>
        </div>
      </div>

      <div class="form-group">
        <div class="col-lg-offset-2 col-lg-10 checkbox">
          <%= label_tag do %>
            <%= check_box_tag :deleted, true %>
            Include deleted users
          <% end %>
        </div>
      </div>

      <div class="form-group">
        <%= label_tag :project_id, "Project", class: "col-lg-2 control-label" %>
        <% projects = [['', nil]] + Project.order(:name).pluck(:name, :id) %>
        <div class="col-lg-4">
          <%= live_select_tag :project_id, options_for_select(projects) %>
        </div>
      </div>

      <div class="form-group">
        <%= label_tag :user_id, "User", class: "col-lg-2 control-label" %>
        <% users = [['', nil]] + User.order(:name).pluck(:name, :id) +
            User.unscoped.order(:name).where("deleted_at IS NOT NULL")
              .pluck(:name, :id).map { |u| ["(deleted) #{u[0]}", u[1]] } %>
        <div class="col-lg-4">
          <%= live_select_tag :user_id, options_for_select(users) %>
        </div>
      </div>

      <div class="form-group">
        <div class="col-lg-offset-2 col-lg-10">
          <%= submit_tag "Download Users CSV Report", class: 'btn btn-default' %>
        </div>
      </div>
    <% end %>
  </div>
  <div class="clearfix">
    <hr />
    <div><strong>Other reports</strong></div>
    <div><%= link_to "Deploys Report", new_csv_export_path %></div>
  </div>
</section>
